package com.david.dao;

import com.david.entity.AdminInfo;
import com.david.entity.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryDao {

    @Select("select * from category where isDelete = 'false' order by id desc")
    List<Category> findAll();

    @Select("select * from category where isDelete = 'false' and parentId = #{parentId} order by id desc")
    List<Category> findCategoryByParentId(int parentId);

    @Select("select * from category where id = #{id} and isDelete = 'false' ")
    Category findById(Integer id);

    @Update("update category set isDelete = 1 where id = #{id} ")
    int delete(Integer id);

    @Update("update category set title = #{title} where id = #{id}")
    int update(Category category);

    @Insert("insert into category (title,parentId,layer,isDelete,isEnable,createTime) values (#{title},#{parentId},#{layer},#{isDelete},#{isEnable},#{createTime})")
    @Options(useGeneratedKeys=true, keyProperty="id")
    int insert(Category category);

    @Update("update category set route = #{route} where id = #{id}")
    int updateRoute(@Param("route") String route,@Param("id") int id);

}
